unit TESTADO;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, RzPanel, RzSplit, StdCtrls, Mask, RzEdit, RzLabel,
  RzButton, UniProvider, SQLServerUniProvider, DBAccess, Uni, DB, ADODB,
  MemDS;

type
  TForm1 = class(TForm)
    RzSplitter1: TRzSplitter;
    Edit_SRVR: TRzEdit;
    Edit_USER: TRzEdit;
    Edit_PSWD: TRzEdit;
    Edit_DATA: TRzEdit;
    Labl_1: TRzLabel;
    Labl_2: TRzLabel;
    Labl_3: TRzLabel;
    Labl_4: TRzLabel;
    RzButton1: TRzButton;
    RzButton2: TRzButton;
    RzButton3: TRzButton;
    RzButton4: TRzButton;
    Memo_1: TRzMemo;
    ADO1: TADOConnection;
    Uni1: TUniConnection;
    SQLServerUniProvider1: TSQLServerUniProvider;
    RzButton5: TRzButton;
    RzButton6: TRzButton;
    ds1: TADODataSet;
    unqry1: TUniQuery;
    procedure RzButton1Click(Sender: TObject);
    procedure RzButton5Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure RzButton6Click(Sender: TObject);
    procedure RzButton2Click(Sender: TObject);
    procedure RzButton3Click(Sender: TObject);
    procedure RzButton4Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.RzButton1Click(Sender: TObject);
var
  SQLA:string;
begin
  //Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=YY2015_YSGL_XTGL;Data Source=.
  //Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=HZ2015_PRMS_YZTF;Data Source=.

  SQLA:='SELECT * FROM GWK_DICT WHERE DICT_MODE=%S';
  SQLA:=Format(SQLA,[QuotedStr('00001')]);

  Self.ds1.Close;
  Self.ds1.Connection:=Self.ADO1;
  Self.ds1.CommandText:=SQLA;
  Self.ds1.Open;
  Self.Memo_1.Lines.Add('ado.select');
  Self.Memo_1.Lines.Add(Format('%D',[ds1.RecordCount]));
end;

procedure TForm1.RzButton5Click(Sender: TObject);
var
  TMPA:string;
  SRVR:string;
  USER:string;
  PSWD:string;
  DATA:string;
begin
  SRVR:=Trim(Edit_SRVR.Text);
  USER:=Trim(Edit_USER.Text);
  PSWD:=Trim(Edit_PSWD.Text);
  DATA:=Trim(Edit_DATA.Text);

  TMPA:='Provider=SQLOLEDB.1;Password=sa;Persist Security Info=False;User ID=%S;Initial Catalog=%S;Data Source=%S';
  TMPA:=Format(TMPA,[USER,DATA,SRVR]);

  try
    Self.ADO1.ConnectionString:=TMPA;
    Self.ADO1.Open;
  except
    on E:Exception do
    begin
      raise E.CreateFmt('%S',[E.Message]);
    end;
  end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Edit_USER.Text:='sa';
end;

procedure TForm1.RzButton6Click(Sender: TObject);
var
  TMPA:string;
  SRVR:string;
  USER:string;
  PSWD:string;
  DATA:string;
begin
  SRVR:=Trim(Edit_SRVR.Text);
  USER:=Trim(Edit_USER.Text);
  PSWD:=Trim(Edit_PSWD.Text);
  DATA:=Trim(Edit_DATA.Text);

  Self.Uni1.LoginPrompt:=False;  
  Self.Uni1.ProviderName:='SQL Server';
  Self.Uni1.Username    :=USER;
  Self.Uni1.Password    :=PSWD;
  Self.Uni1.Database    :=DATA;
  Self.Uni1.Server      :=SRVR;

  try
    Self.Uni1.Open;
  except
    on E:Exception do
    begin
      raise E.CreateFmt('%S',[E.Message]);
    end;  
  end;
end;

procedure TForm1.RzButton2Click(Sender: TObject);
var
  SQLA:string;
begin
  //Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=YY2015_YSGL_XTGL;Data Source=.
  //Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=HZ2015_PRMS_YZTF;Data Source=.

  SQLA:='SELECT MAX(DICT_IDEX)+1 AS MAXX FROM GWK_DICT';

  Self.ds1.Close;
  Self.ds1.Connection:=Self.ADO1;
  Self.ds1.CommandText:=SQLA;
  Self.ds1.Open;
  Self.ds1.First;
  Self.Memo_1.Lines.Add('ado.MAX');
  Self.Memo_1.Lines.Add(Format('%s',[ds1.FieldByName('MAXX').AsString]));
end;

procedure TForm1.RzButton3Click(Sender: TObject);
var
  SQLA:string;
begin
  //Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=YY2015_YSGL_XTGL;Data Source=.
  //Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=HZ2015_PRMS_YZTF;Data Source=.

  SQLA:='SELECT * FROM GWK_DICT WHERE DICT_MODE=%S';
  SQLA:=Format(SQLA,[QuotedStr('00001')]);

  Self.unqry1.Close;
  Self.unqry1.Connection:=Self.Uni1;
  Self.unqry1.SQL.Clear;
  Self.unqry1.SQL.Add(SQLA);
  Self.unqry1.Open;
  Self.Memo_1.Lines.Add('uni.select');
  Self.Memo_1.Lines.Add(Format('%D',[unqry1.RecordCount]));
end;

procedure TForm1.RzButton4Click(Sender: TObject);
var
  SQLA:string;
begin
  //Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=YY2015_YSGL_XTGL;Data Source=.
  //Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=HZ2015_PRMS_YZTF;Data Source=.

  SQLA:='SELECT MAX(DICT_IDEX)+1 AS MAXX FROM GWK_DICT';

  Self.unqry1.Close;
  Self.unqry1.Connection:=Self.Uni1;
  Self.unqry1.SQL.Clear;
  Self.unqry1.SQL.Add(SQLA);
  Self.unqry1.Open;
  Self.unqry1.First;
  Self.Memo_1.Lines.Add('uni.MAX');
  Self.Memo_1.Lines.Add(Format('%S',[unqry1.FieldByName('MAXX').AsString]));
end;
end.
